package com.acme.bankapp.service.bank;

public class CheckingAccount extends AbstractAccount {
    private double overdraft;

    public CheckingAccount(double balance, double overdraft) {
        super(balance);
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double x) {
        if (getBalance() >= x) {
            setBalance(getBalance() - x);
        } else if (getBalance() + overdraft >= x) {
            x -= getBalance();
            setBalance(0);
            overdraft -= x;
        }
    }

    @Override
    public double maximumAmountToWithdraw() {
        return getBalance() + overdraft;
    }
}